package com.systemmanger.controller;

import com.bean.WmsTPermission;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.systemmanger.service.QuanXianGuanLiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("guanli")
public class QuanXianController {
    @Autowired
    QuanXianGuanLiService quanXianGuanLiService;

    @RequestMapping("Perm.do")
    public String page(HttpSession httpSession,
                       @RequestParam(required = false,defaultValue = "1",value ="pageNum" )Integer pageNum,
                       @RequestParam(defaultValue = "15",value = "pageSize")Integer pageSize,
                       String permName, String permID){
        PageInfo<WmsTPermission> pageInfo=new PageInfo<>();
        if(pageNum==null || pageNum<0){
            pageNum=1;
        }
        if(pageSize==null){
            pageSize=15;
        }
        WmsTPermission wmsTPermission=new WmsTPermission();
        wmsTPermission.setPermName(permName);
        wmsTPermission.setPermID(permID);
        httpSession.setAttribute("permName",permName);
        httpSession.setAttribute("permID",permID);
        //引入分页查询插件， pageNum是第几页，pageSize是每页显示多少条
        PageHelper.startPage(pageNum,pageSize);
        List<WmsTPermission> list=quanXianGuanLiService.getPage(wmsTPermission);
        pageInfo=new PageInfo<>(list,pageSize);
        System.out.println(list);
        System.out.println(pageInfo);
        httpSession.setAttribute("pageInfo",pageInfo);
        return "guanli/PermissionManger";
    }

    @RequestMapping("Perm1.do")
    public String deletePerm(String permID,HttpSession httpSession,
                             int pageSize,int pageNum,String permId1,String permName){
        quanXianGuanLiService.delete(permID);
        return page(httpSession,pageNum,pageSize,permId1,permName);
    }

}
